package cn.itsource.ymcc.consumer;

import cn.itsource.ymcc.constant.Constants;
import cn.itsource.ymcc.constant.CourseConstants;
import cn.itsource.ymcc.constant.OrderConstants;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;
import java.util.List;

@Slf4j
@Component
@RocketMQMessageListener(
        consumerGroup = "OrderSYSTEMConsumer",
        topic = OrderConstants.TOPIC_ORDER_SYSTEM_PUSH,
        selectorExpression = OrderConstants.TAGS_ORDER_SYSTEM_PUSH
)
public class OrderSYSTEMConsumer implements RocketMQListener<MessageExt> {

    @Override
    public void onMessage(MessageExt messageExt) {
        try {
            byte[] body = messageExt.getBody();
            String message = new String(body, Constants.UTF8);
            String[] split = message.split(":");
            //获取用户信息
            System.out.println("标题："+split[0]);
            System.out.println("用户id："+split[1]);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}
